<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"
	import="java.util.*,com.telecom.cms.dto.*,com.telecom.cms.dao.*"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
<head>
	<title>JSP for SysTeamForm form</title>
	<LINK href="css/default.css" rel=stylesheet>
	<LINK href="css/button.css" rel=stylesheet>
	<LINK href="css/main.css" type=text/css rel=stylesheet>
<script type="text/javascript">
	function opchange(o){
		var obj=document.all.ObjSelect;
		for(i=0;i<obj.length;i++){
			obj.options[i].selected=true;
		}
		document.idaCustomForm.method.value=o;
		document.idaCustomForm.submit();
	}
	
	function selTemplate(tmptid){
		document.idaCustomForm.method.value='runIdaCustom';
		document.idaCustomForm.templateId.value=tmptid;
		document.idaCustomForm.submit();
		//document.location.href = 'idaCustom.do?method=runIdaCustom&templateId=' + tmptid;
	}

	function Atomoption (text,value){
		this.text=text;
		this.value=value;
	}
	
	var atoms=new Array();
	
	function ChangeGroup()
	{ 
		var i,iGroupIndex;
		iGroupIndex=document.all.groups.selectedIndex;
		iAtomCount=0; 
		while (atoms[iGroupIndex][iAtomCount]!=null) 
		 iAtomCount++;
		 //计算选定组下的原子个数 
		document.all.SrcSelect.length=0;//清空选项数 
		var obj=document.all.ObjSelect;
		var objCount=obj.length;
		for(i=0;i<=iAtomCount-1;i++){//改变下拉菜单的内容 
			var flag=0;
			for(j=0;j<=objCount-1;j++){
				var ov = obj.options[j].value.split("#");
				if(ov[0]==atoms[iGroupIndex][i].value){
					flag++;
				}
			}
			if(flag==0)
			document.all.SrcSelect.add(new Option(atoms[iGroupIndex][i].text,atoms[iGroupIndex][i].value));
		}
		document.all.SrcSelect.focus();
	}
	
	function moveUp()  
	{ 
	var theObj=document.all.ObjSelect;
	for(var i=1;i<theObj.length;i++)
	 {
	  if( theObj.options[i].selected && !theObj.options[i-1].selected )
	  {
	   theObj.options[i].swapNode(theObj.options[i-1]);//与上面一个交换
	  }
	 }
	}
	  
	function moveDown()
	{ 
	var theObj=document.all.ObjSelect;
	for(var i=theObj.length-2;i>-1;i--)
	 {
	  if( theObj.options[i].selected && !theObj.options[i+1].selected )
	  {
	   theObj.options[i].swapNode(theObj.options[i+1]);
	  }
	 }
	}
	
	function moveLeftOrRight(fromObj,toObj)
	{
	 var lengthOfToObj=toObj.length;
	 for(var i=fromObj.length-1;i>-1;i--)
	 {
	  if(fromObj.options[i].selected)
	  {
	   toObj.add(new Option(fromObj.options[i].text,fromObj.options[i].value),lengthOfToObj);//new option(text,value,true,true)
	   toObj.options[lengthOfToObj].selected=true;
	   fromObj.options[i].removeNode(true);
	  }
	 }
	}
	
	function submitchange(){
		obj=document.defPickupForm.ObjSelect;
		for(i=0;i<obj.length;i++){
			obj.options[i].selected=true;
		}
		document.defPickupForm.target="rsFrame";
	}
	
	function changeOrderRule(sel){
		var i=sel.selectedIndex;
		var value=sel.options[i].value;
		var text=sel.options[i].innerHTML;
		vstate=value.split("#");
		tstate=text.split("[");
		if(vstate[1]==null){
		sel.options[i].value=vstate[0]+"#asc";
		sel.options[i].innerHTML=tstate[0]+"[正序]";
		}
		if(vstate[1]=="asc"){
		sel.options[i].value=vstate[0]+"#desc";
		sel.options[i].innerHTML=tstate[0]+"[逆序]";
		}
		if(vstate[1]=="desc"){
		sel.options[i].value=vstate[0];
		sel.options[i].innerHTML=tstate[0];
		}
	}
	function changeInput(o){
		if(o=='text'){
			document.getElementById("uploaddept").style.display="none";
			document.getElementById("textdept").style.display="";
		}
		if(o=='file'){
			document.getElementById("uploaddept").style.display="";
			document.getElementById("textdept").style.display="none";
		}
	}
	
	function searchField(){
		document.all.SrcSelect.length=0;
		var key=document.getElementById("field").value;
		if(key){
			var count=0;
			for(i=0;i<atoms.length;i++){
				data=atoms[i];
				for(j=0;j<atoms[i].length;j++){
					result=atoms[i][j].text.indexOf(key)
					if(result>-1){
						document.all.SrcSelect.add(new Option(atoms[i][j].text,atoms[i][j].value));
						count++;
					}
				}
			}
		}
	}
	
	function showHiddenDiv(id){
		var divstyle=document.getElementById(id).style.display;
		if(divstyle=="none"){
			document.getElementById(id).style.display="";
		}else{
			document.getElementById(id).style.display="none";
		}
	}
</script>
</head>
<body>
<html:form action="/idaCustom" enctype="multipart/form-data" onsubmit="submitchange()">
<table width="770" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
	<tr>
		<td width="3" height="31">
			<img height="31" src="./images/table_01.gif" width="3" />
		</td>
		<td background="./images/table_02.gif" height="31">
			<table cellspacing="0" cellpadding="0" width="146" align="left"
				border="0">
				<tbody>
					<tr>
						<td width="51" background="./images/title_1_bg.gif">
							<img height="31" src="./images/title_1.gif" width="51" />
						</td>
						<td width="95" background="./images/title_1_bg.gif">
							<span class="color_b_666">自定义取数</span>
						</td>
					</tr>
				</tbody>
			</table>
		</td>
		<td width="3">
			<img height="31" src="./images/table_03.gif" width="3" />
		</td>
	</tr>
	<tr>
		<td background="images/table_04.gif">
			<img height="5" src="images/table_04.gif" width="3">
		</td>
		<td style="PADDING-TOP: 3px" valign="top">
			<table width='100%' border='0' cellspacing='' cellpadding='2'><tr><td>
			<table width='100%' border='0' cellspacing='1' cellpadding='2'>
				<tr>
					<td align='center' width='20%'>基本条件</td>
					<td width='80%'>
						<table width='100%' border='0' cellspacing='0' cellpadding='0'>
							<td width='8%'>帐务月：</td>
							<td>
								<html:select property="billingCycleId">
									<logic:present name="billingCycleIdList" scope="request">
										<logic:iterate name="billingCycleIdList" id="month">
											<html:option value="${month}">
												<bean:write name="month"/>
											</html:option>
										</logic:iterate>
									</logic:present>
								</html:select>
							</td>
							<td width='8%'>本地网：</td>
							<td>
								<html:select property="latnCd">
									<logic:present name="latnCdList" scope="request">
										<logic:iterate name="latnCdList" id="latn">
											<html:option value="${latn.latn_Cd}">
												<bean:write name="latn" property="latnname"/>
											</html:option>
										</logic:iterate>
									</logic:present>
								</html:select>
							</td>
							<td width='50%'></td>
						</table>
					</td>
				</tr>
				<tr>
					<td align='center'>取数类别</td>
					<td>
						<html:select property="anlsTypeId">
							<html:option value="10">用户&nbsp;&nbsp;</html:option>
							<html:option value="20">客户&nbsp;&nbsp;</html:option>
						</html:select>
					</td>
				</tr>
				<tr>
					<td align='center'>结果模板</td>
					<td>
						<html:select property="templateId" onchange="selTemplate(this.value);">
							<html:option value="">请选择</html:option>
							<logic:present name="templateList" scope="request">
								<logic:iterate name="templateList" id="t">
									<logic:equal name="t" property="templateTypeId" value="20">
										<html:option value="${t.templateId}">
											<bean:write name="t" property="templateName" />
										</html:option>
									</logic:equal>
								</logic:iterate>
							</logic:present>
						</html:select>
					</td>
				</tr>
				<tr>
					<td align='center'>取数方式</td>
					<td>
						<html:radio property="customType" value="numCheck" onclick="changeInput('text')" />号码反查&nbsp;&nbsp;
						<html:radio property="customType" value="custSql" onclick="changeInput('text')" />自定义SQL&nbsp;&nbsp;
						<html:radio property="customType" value="upFile" onclick="changeInput('file')" />上传文件&nbsp;&nbsp;
					</td>
				</tr>
				<tr>
					<td align='center'>号码类型</td>
					<td>
						<html:radio property="numType" value="Accs_Nbr" />电话号码&nbsp;&nbsp;
						<html:radio property="numType" value="Prd_Inst_Id" />产品实例号&nbsp;&nbsp;
						<html:radio property="numType" value="Cust_Id" />客户编号&nbsp;&nbsp;
					</td>
				</tr>
				<tr id="textdept" style="display: ;">
					<td align='center'>请直接输入号码<br>或SQL语句<br><br>（注：直接输入号码格式为每行一个号码）</td>
					<td>
						<html:textarea property="inputText" cols="73" rows="12"></html:textarea>
					</td>
				</tr>
				<tr id="uploaddept" style="display: none;">
					<td align='center'>上传文件</td>
					<td>
						<html:file property="upFile"></html:file>
						<html:radio property="fileType" value="excel" />EXCEL格式&nbsp;&nbsp;
						<html:radio property="fileType" value="txt" />TXT格式&nbsp;&nbsp;
					</td>
				</tr>
			</table>
			</td></tr></table>

			<table width='100%' border='0' cellspacing='' cellpadding='2'>
				<tr>
					<td align="left" colspan="2">
						<table width='100%' border='0' cellspacing='0' cellpadding='2'>
							<tr align="center" height="25">
								<td background="images/atom_02.gif" width="20%">结果字段类型：</td>
								<td background="images/atom_02.gif" width="25%">可选择结果字段：</td>
								<td background="images/atom_02.gif" width="10%">&nbsp;</td>
								<td background="images/atom_02.gif" width="25%">已选择结果字段：</td>
								<td background="images/atom_02.gif" width="20%">&nbsp;</td>
							</tr>
							<tr align="center" valign="top">
								<td>
									<select name="groups" id="groups" onchange="ChangeGroup()">
									<%
										IdaDAO idadao = new IdaDAO();
										List grouplist = idadao.findAllAtomGroup();
										int idx = 0;
										for (int i = 0; i < grouplist.size(); i++) {
											SEG_BIZ_GROUP_DEFDTO groupdto = (SEG_BIZ_GROUP_DEFDTO) grouplist.get(i);
											SEG_BOOKMARK_DEFDTO bookmark = idadao.findBookmark(groupdto.getBOOKMARK_ID());
											if (bookmark.getCLASS_ID() != 1 && bookmark.getCLASS_ID() != 2)
												continue;
									%>
										<option value=<%=groupdto.getATOM_GROUP_ID()%>><%=bookmark.getBOOKMARK_NAME() + "→" + groupdto.getATOM_GROUP_NAME()%></option>
										<script type="text/javascript">atoms[<%=idx%>]=new Array(); </script>
										<%
											List groupAtoms = idadao.findGroupAtoms(groupdto.getATOM_GROUP_ID());
											if (groupAtoms != null && groupAtoms.size() > 0)
												for (int j = 0; j < groupAtoms.size(); j++) {
													SEG_BIZ_ATOM_DEFDTO showdto = (SEG_BIZ_ATOM_DEFDTO)groupAtoms.get(j);
										%>
										<script type="text/javascript">atoms[<%=idx%>][<%=j%>]=new Atomoption('<%=showdto.getBIZ_ATOM_NAME()%>',<%=showdto.getBIZ_ATOM_ID()%>) </script>
									<%
											}
											idx++;
										}
									%>
									</select>&nbsp;
									<br/>
									搜索字段：
									<input type="text" name="field" onpropertychange="searchField()" size="15">
									<br/><br/>
									<div align='left' style="display: none;" id="multimonth" style='height: 160px; overflow-y: auto;'>
										请选择您要查看的帐务月：
										<logic:present name="billingCycleIdList" scope="request">
											<logic:iterate name="billingCycleIdList" id="month">
												<input type="checkbox" name="viewMonth" value="${month}">${month}&nbsp;&nbsp;<br>
											</logic:iterate>
										</logic:present>
									</div>
								</td>
								<td>
									<select name="SrcSelect" size=15 style="font-size: 10pt; width: 200px;" multiple>
									</select>
								</td>
								<td align="center" valign="middle">
									<a href="javascript:moveLeftOrRight(document.all.SrcSelect,document.all.ObjSelect)"><img src="images/button_add_arrow.gif" border="0"></a>
									<br><br>
									<a href="javascript:moveLeftOrRight(document.all.ObjSelect,document.all.SrcSelect)"><img src="images/button_del_arrow.gif" border="0"></a>
								</td>
								<td>
									<select name="ObjSelect" ondblclick="changeOrderRule(this)" size=15 style="font-size: 10pt; width: 200px;" multiple title="提示：双击结果字段可对选择的结果字段排序">
										<%
											IdaTemplate rsTemplate = (IdaTemplate)request.getAttribute("idaTemplate");
											if (rsTemplate != null){
												List rsAtomList = rsTemplate.getAtomList();
												for (int i = 0; i < rsAtomList.size(); i++){
													IdaTemplateAtomResult atom = (IdaTemplateAtomResult)rsAtomList.get(i);
													String vo = "";
													String to = atom.getResultOrderRule();
													if(to.equals("asc")){
														to="正序";
													}else if(to.equals("desc")){
														to="逆序";
													}
													if (atom.getResultOrderRule() != null && !atom.getResultOrderRule().equals("")){
														vo = "#" + atom.getResultOrderRule();
														to = "[" + to + "]";
													}
										%>
											<option value="<%=atom.getBizAtomId() + vo%>"><%=atom.getBizAtomName() + to%></option>
										<% }} %>
									</select>
									<script type="text/javascript">
										document.all.groups.selectedIndex=0;
										ChangeGroup();
									</script>
								</td>
								<td align="left">
									<a href="javascript:moveUp()"><img src="images/button_up.gif" border="0"></a>
									<br><br>
									<a href="javascript:moveDown()"><img src="images/button_down.gif" border="0"></a>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td align="center" width="20%">
						<div align='center'>
							<input type="checkbox" name="viewMultiMonth" value="T" onclick="showHiddenDiv('multimonth')">查看多个帐务月数据
						</div>
					</td>
					<td align="center" width="80%">
						<div align="center" id="commit">
							<input type="radio" name="queryType" value="10" checked>清单数据&nbsp;&nbsp;
							<input type="radio" name="queryType" value="20">汇总数据&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="button" onclick="opchange('doQuery')" value="提交取数">&nbsp;&nbsp;
						</div>
					</td>
				</tr>
			</table>
		</td>
		<td background="images/table_05.gif">
			<img height="5" src="images/table_05.gif" width="3">
		</td>
	</tr>
	<tr height="3">
		<td height="3">
			<img height="12" src="images/table_06.gif" width="3">
		</td>
		<td height="3">
			<img height="3" src="images/table_07.gif" width="764">
		</td>
		<td height="3">
			<img height="12" src="images/table_08.gif" width="3">
		</td>
	</tr>
</tbody>
</table>
<html:hidden property="method" value="doQuery" />
<html:hidden property="templateId" value="${idaTemplate.templateId}" />
</html:form>
</body>
</html>